import { reqGetGoodsInfo } from '@/api'

const state = {
  //商品数据
  goodsInfo: {},
}

const actions = {
  //获取搜索商品数据
  async GetGoodsInfo({ commit }, searchParams) {
    const res = await reqGetGoodsInfo(searchParams)
    if (res.code === 200) {
      commit('SAVE_GOODS_INFO', res.data)
    } else {
      console.log(res.message)
    }
  },
}

const mutations = {
  //存储搜索商品数据
  SAVE_GOODS_INFO(state, payload) {
    state.goodsInfo = payload
  },
}

const getters = {
  // 商品属性数据
  attrsList(state) {
    return state.goodsInfo.attrsList
  },
  // 商品数据
  goodsList(state) {
    return state.goodsInfo.goodsList
  },
  // 品牌数据
  trademarkList(state) {
    return state.goodsInfo.trademarkList
  },
  // 数据总条数
  total(state) {
    return state.goodsInfo.total
  },
}

export default {
  namespaced: true,
  state,
  actions,
  mutations,
  getters,
}
